local skill = fk.CreateSkill {
  name = "sj_zhoushuhuizhan__jizhifanyun_fire_attack_skill",
}

skill.visible = true

skill:addEffect("cardskill", {
  prompt = "#fire_attack_skill",
  target_num = 1,
  mod_target_filter = function(self, _, to_select, _, _, _)
    return not to_select:isKongcheng()
  end,
  target_filter = Util.CardTargetFilter,
  on_effect = function(self, room, effect)
    local from = effect.from
    local to = effect.to
    --if to:isKongcheng() then return end
    local colors = {
      [Card.Black] = "黑色",
      [Card.Red] = "红色",
      [Card.NoColor] = "无色",
    }
    local suits = {
      [Card.Spade] = "黑桃",
      [Card.Club] = "梅花",
      [Card.Heart] = "红桃",
      [Card.Diamond] = "方块",
      [Card.NoSuit] = "无花色",
    }
    local color = effect.card.color
    local suit = effect.card.suit
    local to_handcards = to:getCardIds("h")
    local to_cards = table.filter(to_handcards,function (id)
      return Fk:getCardById(id).color == color
    end)
    if #to_cards > 0 then
      local params = { ---@type AskToCardsParams
        min_num = 1,
        max_num = 1,
        include_equip = false,
        skill_name = "fire_attack_skill",
        cancelable = false,
        pattern = tostring(Exppattern{id = to_cards}),
        prompt = "#sj_zhoushuhuizhan__jizhifanyun-show:" .. from.id.."::"..colors[color]
      }
      local showCard = Fk:getCardById(room:askToCards(to, params)[1])
      to:showCards(showCard)
      local handcards = from:getCardIds("h")
      local cards = table.filter(handcards,function (id)
        local card = Fk:getCardById(id)
        return card.suit ~= suit and card.suit ~= showCard.suit
      end)
      if #cards > 0 then
        local prompt = suits[suit]
        if suit ~= showCard.suit then
          prompt = prompt.."或"..suits[showCard.suit]
        end
        params = { ---@type AskToDiscardParams
          min_num = 1,
          max_num = 1,
          include_equip = false,
          skill_name = "fire_attack_skill",
          cancelable = false,
          pattern = tostring(Exppattern{id = cards}),
          prompt = "#sj_zhoushuhuizhan__jizhifanyun-discard:" .. to.id .. "::" .. prompt,
        }
        cards = room:askToDiscard(from, params)
        if #cards > 0 and not to.dead then
          room:damage({
            from = from,
            to = to,
            card = effect.card,
            damage = 1,
            damageType = fk.FireDamage,
            skillName = "fire_attack_skill",
          })
        end
        return
      else
        from:showCards(handcards)
      end
    else
      if #to_handcards > 0 then
        to:showCards(to_handcards)
      end
    end
    from:drawCards(2,"sj_zhoushuhuizhan__jizhifanyun")
  end,
})


return skill